/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nl.hr.cmi.android.aanwezigheidsregistratie.helper;

import android.util.Log;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author Johan
 */
public class JSONHelper {
    private String json = "[{\"naam\" : \"Johan\", \"leeftijd\" : \"23\"}, {\"naam\" : \"Stelian\", \"leeftijd\" : \"29\"}]";
    private JSONArray jsonarr;

    public JSONHelper(){
        try {
            jsonarr = new JSONArray(json);
        } catch (JSONException ex) {
            Log.e("JSON ERROR", ex.getMessage());
        }
    }

    public ArrayList<String> getNamen(){
        ArrayList<String> namen = new ArrayList<String>();
        for (int i = 0; i<jsonarr.length(); i++){
            try {
                JSONObject obj = (JSONObject) jsonarr.get(i);
                namen.add(obj.getString("naam"));
            } catch (JSONException ex) {
                Log.e("JSON ERROR2", ex.getMessage());
            }
        }
        return namen;
    }
}
